<?php
class Modules_Workspace_Model_CreateWorkspace
	{
	
		public $result=array("error"=>"","result"=>0);
		public function Modules_Workspace_Model_CreateWorkspace($args=null)
		{
			
			if($args==null)
				return;
			try{
				
				if(count(Modules_Common_DB_Workspace::SearchByName($args['name']))>0)
				{
					$this->result["result"]=0;
					$this->result["error"]="This Group already exist";
					return;
				}
				$data=
				array("name"=>$args["name"],"administrator"=>$_SESSION['id'],"description"=>$args["description"]);
				$a=BaseObject::AddRecords($data, Modules_Common_DB_Workspace:: GetTableName());
				if($a>-1)
					$this->result["result"]=1;
				else
					throw new Exception();
				$data=array("workspace_id"=>$a,"users_id"=>$_SESSION['id']);
				$a=BaseObject::AddRecords($data, Modules_Common_DB_WorkspaceHasUsers:: GetTableName());
				
				$user=new Modules_Common_DB_Users($_SESSION['id']);
				$user->LastWorkspace=$a;
				$user->Save();
				$_SESSION['workspace']=$a;
			}
			catch(Exception $e)
			{
				$this->result["result"]=0;
				$this->result["error"]="No valid Account";
			}
		}
		public function Init()
		{
			
		}
	}
	?>